// Linep_BPA.cpp: implementation of the CLinep_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Dat/Linep_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLinep_BPA::CLinep_BPA()
{
	m_chType = 'L';
	m_chSubType = '+';
	m_chChangeCode = ' ';

	m_chCKTLD = ' ';
	m_chSection = ' ';
	m_dMvar1 = 0.0;
    m_dMvar2 = 0.0;
}

CLinep_BPA::~CLinep_BPA()
{

}

CLinep_BPA::CLinep_BPA(CLinep_BPA &linep):CBranch_BPA(linep)
{
	m_chCKTLD = linep.m_chCKTLD;
    m_chSection = linep.m_chSection;
	m_dMvar1 = linep.m_dMvar1;
	m_dMvar2 = linep.m_dMvar2;
}

bool CLinep_BPA::UpdateEx(char *buffer)
{
	bool bResult = CBranch_BPA::UpdateEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CLinep_BPA: UpdateEx): impossible!\n");
		return false;
	}

	buffer[31] = m_chCKTLD;
	buffer[32] = m_chSection;
	DoubleToStr(m_dMvar1,&buffer[33],5);
	strcpy(&buffer[38],"     ");
	DoubleToStr(m_dMvar2,&buffer[43],5);
	
	return true;

}

bool CLinep_BPA::FillEx(char *buffer)
{
	bool bResult = CBranch_BPA::FillEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CLinep_BPA: FillEx): no basic information!\n");
		return false;
	}
	
	if (strlen(buffer)<32)
	{
		printf("Error in (CLinep_BPA: FillEx): line has no parameter!\n");
		return false;
	}

	if (EndOfSec(&buffer[31],1))
	{
		printf("Error in (CLinep_BPA: FillEx): line has no parameter!\n");
		return false;
	}
	m_chCKTLD = buffer[31];

	if (EndOfSec(&buffer[32],1))
	{
		printf("Error in (CLinep_BPA: FillEx): line has no parameter!\n");
		return false;
	}
	m_chSection = buffer[32];
	
	m_dMvar1 = StrToDouble(&buffer[33],5);
	if (EndOfSec(&buffer[33],5))
	{
		return true;
	}

	m_dMvar2 = StrToDouble(&buffer[43],5);

	return true;

}

bool CLinep_BPA::Equals(CListItem *pItem)
{
	CLinep_BPA* pLinep = (CLinep_BPA*)pItem;
	
	char strThisName1[9],strThisName2[9],strName1[9],strName2[9];
	strcpywithoutwhitespace(strThisName1,m_strName1);
	strcpywithoutwhitespace(strThisName2,m_strName2);
	strcpywithoutwhitespace(strName1,pLinep->m_strName1);
	strcpywithoutwhitespace(strName2,pLinep->m_strName2);
	
	if ((!strcmp(strThisName1,strName1) && \
		m_dkV1==pLinep->m_dkV1 && \
		!strcmp(strThisName2,strName2) && \
		m_dkV2==pLinep->m_dkV2 && \
		m_chCKTLD==pLinep->m_chCKTLD) || \
		(!strcmp(strThisName1,strThisName2) && \
		m_dkV1==pLinep->m_dkV2 && \
		!strcmp(strThisName2,strName1) && \
		m_dkV2==pLinep->m_dkV1 && \
		m_chCKTLD==pLinep->m_chCKTLD))
		return true;
	
	return false;
}
